/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wso.dao;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import wso.dto.WsoRole;
import wso.global.BaseDao;

/**
 *
 * @author Violet_Ink
 */
public class RoleDaoImpl extends BaseDao implements RoleDao {

    public void saveOrUpdateRole(WsoRole role) {
        saveOrUpdate(role);
    }

    public void deleteRole(String roleid) {
        Session session = getSession();
        Query query = null;
        StringBuilder str = new StringBuilder();
        str.append("delete WsoRole role where role.roleid= :roleid");
        query = session.createQuery(str.toString());
        query.setString("roleid", roleid);

        query.executeUpdate();
    }

    public WsoRole[] getAllRole() {
        Session session = getSession();
        Query query = null;
        StringBuilder str = new StringBuilder();
        str.append("from WsoRole role");
        query = session.createQuery(str.toString());
        List roleList = query.list();
        WsoRole[] result = new WsoRole[roleList.size()];
        roleList.toArray(result);

        return result;
    }

    public WsoRole getRole(String roleid) {
        Session session = getSession();
        Query query = null;
        StringBuilder str = new StringBuilder();

        str.append("from WsoRole role where role.roleid = :roleid");
        query = session.createQuery(str.toString());
        query.setString("roleid", roleid);

        return (WsoRole) query.uniqueResult();
    }
}
